Attribute VB_Name = "mMain"
Option Explicit
Option Base 1

Private Sub Auto_Open()
    Call Auto_Close
    On Error Resume Next
    With Application.CommandBars("Worksheet Menu Bar")
        If Err Then MsgBox "Excel menu not recognised !   ", vbCritical: Exit Sub
        With .Controls.Add(msoControlPopup, , , , True)
            If Err Then MsgBox "Failed to add QualityCenter menu ! ", vbCritical: Exit Sub
            .Caption = "QualityCenter"
            With .Controls.Add(Type:=msoControlButton, temporary:=True)
                If Err Then MsgBox "Failed to add control in QualityCenter menu ! ", vbCritical: Exit Sub
                '.BeginGroup = True
                .Caption = "Extract Data"
                .OnAction = "ExtractData"
                .FaceId = 6262
            End With
        End With
    End With
End Sub

Private Sub Auto_Close()
    On Error Resume Next
    Application.CommandBars("Worksheet Menu Bar").Controls("QualityCenter").Delete
End Sub

Private Sub ExtractData()
    Dim lData As Variant, lo As ListObject
    fQualityCenter.Show
    lData = fQualityCenter.GetData
    Unload fQualityCenter
    Application.ScreenUpdating = False
    If Not IsEmpty(lData) Then
        For Each lo In ActiveSheet.ListObjects
            lo.Delete
        Next lo
        With Cells.Resize(UBound(lData, 1), UBound(lData, 2))
            .Value = lData
            .WrapText = False
            ActiveSheet.ListObjects.Add xlSrcRange, .Cells, , xlYes
        End With
    End If
    Application.ScreenUpdating = True
End Sub
